import collections

# def maxArea(height):    # 遍历超出时间限制
#     n = len(height)
#     if n <= 1:
#         return 0
#     res = 0
#     for i in range(n):
#         for j in range(i + 1,n):
#             temp = (j - i) * min(height[i] , height[j])
#             if temp > res:
#                 res = temp
#     return res


# 这一题其实很简单，双指针分析方法真的太简单了,每次移动小的数字
def maxArea(height):
    left, right = 0, len(height) - 1
    ans = 0
    while left < right:
        ans = max(ans,min(height[left], height[right]) * (right - left))
        if height[left] < height[right]:
            pre = height[left]
            left = left + 1
            while height[left] <= pre:
                pre = height[left]
                left = left + 1
        else:
            pre = height[right]
            right = right - 1
            while height[right] <= pre:
                pre = height[right]
                right = right - 1
    return ans